#include "player.h"
#include "gamelua.h"
#include <iostream>
#include <cstdlib>

using namespace std;

void Player::set_name(string str)
{
    name = str;
}

string Player::get_name()
{
    return name;
}

void Player::set_hitpoint (int value)
{
	hitpoint = value;
}

int Player::get_hitpoint ()
{
	return hitpoint;
}

void Player::set_manapoint(enum MagicColor type, int value)
{
	switch (type) {
		case MAGIC_GREEN:
			manapoint_green = value;
			break;
		case MAGIC_BLUE:
			manapoint_blue = value;
			break;
		case MAGIC_RED:
			manapoint_red = value;
			break;
		default:
			break;
	}
}

int Player::get_manapoint(enum MagicColor type)
{
	int value;
	switch (type) {
		case MAGIC_GREEN:
			value = manapoint_green;
			break;
		case MAGIC_BLUE:
			value = manapoint_blue;
			break;
		case MAGIC_RED:
			value = manapoint_red;
			break;
		default:
			value = -1;
			break;
	}
	return value;
}

void Player::set_inc_mana(enum MagicColor type, int value)
{
	switch (type) {
		case MAGIC_GREEN:
			inc_mana_green = value;
			break;
		case MAGIC_BLUE:
			inc_mana_blue = value;
			break;
		case MAGIC_RED:
			inc_mana_red = value;
			break;
		default:
			break;
	}
}

int Player::get_inc_mana(enum MagicColor type)
{
	int value;
	switch (type) {
		case MAGIC_GREEN:
			value = inc_mana_green;
			break;
		case MAGIC_BLUE:
			value = inc_mana_blue;
			break;
		case MAGIC_RED:
			value = inc_mana_red;
			break;
		default:
			value = -1;
			break;
	}
	return value;
}

void Player::increase_mana ()
{
	manapoint_green += inc_mana_green;
	manapoint_blue  += inc_mana_blue;
	manapoint_red   += inc_mana_red;
}

void Player::change_hitpoint (int value)
{
	hitpoint += value;
    hitpoint = hitpoint > 0 ? hitpoint : 0;
    return;
}

void Player::change_manapoint (enum MagicColor type, int value)
{
    switch (type) {
		case MAGIC_GREEN:
			manapoint_green += value;
            manapoint_green = manapoint_green > 0 ? manapoint_green : 0;
			break;
		case MAGIC_BLUE:
			manapoint_blue += value;
            manapoint_blue = manapoint_blue > 0 ? manapoint_blue : 0;
			break;
		case MAGIC_RED:
			manapoint_red += value;
            manapoint_red = manapoint_red > 0 ? manapoint_red : 0;
			break;
		default:
			break;
	}
    return;
}

bool Player::is_alive ()
{
	return hitpoint > 0 ? true : false;
}


/**
 * print player
 * for debug
 */
void Player::print_player()
{
    cout << "Hit Point:" << hitpoint << endl;
	cout << "Red:" << manapoint_red << endl;
	cout << "Blue:" << manapoint_blue << endl;
	cout << "Green:" << manapoint_green << endl;
	cout << "Inc Red:" << inc_mana_red << endl;
	cout << "Inc Blue:" << inc_mana_blue << endl;
	cout << "Inc Green:" << inc_mana_green << endl;
}
